
    /**  
    * @Title: FeignBeanFactoryPostProcessor.java
    * @Package com.efast.cafe.framework.feign
    * @Description: TODO(用一句话描述该文件做什么)
    * @author Administrator
    * @date 2018年10月15日
    * @version V1.0  
    */
    
package com.efast.cafe.framework.feign;

import java.util.Arrays;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
    * @ClassName: FeignBeanFactoryPostProcessor
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @author Administrator
    * @date 2018年10月15日
    *
    */
@Component
public class FeignBeanFactoryPostProcessor implements BeanFactoryPostProcessor{

	@Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
            BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
            bd.setDependsOn("eurekaAutoServiceRegistration");
        }
    }

    private boolean containsBeanDefinition(ConfigurableListableBeanFactory beanFactory, String... beans) {
        return Arrays.stream(beans).allMatch(b -> beanFactory.containsBeanDefinition(b));
    }
}
